package com.qf.purchasing.controller;

import com.github.pagehelper.PageInfo;
import com.qf.common.base.result.RespResult;
import com.qf.purchasing.qo.PostQO;
import com.qf.purchasing.service.PostService;
import com.qf.purchasing.vo.PostVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/post")
//类上，tags=模块名
@Api(tags = "投标管理")
public class PostController {
    @Resource
    private PostService PostService;

    @GetMapping("/list")
    //接口上，接口描述。value=接口名
    @ApiOperation("分页查询商品")
    //接口上，参数注解
    @ApiImplicitParams({
            //                参数名，       参数说明，         是否必填， 参数请求类型：query,header,path  参数数据类型，   参数默认值           示例
            @ApiImplicitParam(name = "page", value = "当前页数", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "1", example = "page=1"),
            @ApiImplicitParam(name = "size", value = "展示量", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "10"),
            @ApiImplicitParam(name = "title", value = "搜索标题", required = false),
            @ApiImplicitParam(name = "year", value = "搜索年份", required = false)
    })
    public PageInfo<PostVO> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size, @RequestParam(required = false) String title, @RequestParam(required = false) String year) {
        return PostService.query(page, size, title, year);
    }


    @PutMapping("/delete1")
    @ApiOperation("删除采购计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "采购计划id", required = true)
    )
    public RespResult<String> RemovePostOne(int id) {
        return PostService.deletePostOne(id);
    }


    @PutMapping("/delete2")
    @ApiOperation("多选删除采购计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "ids", value = "采购计划id数组", required = true)
    )
    public RespResult<String> RemovePosts(int[] ids) {
        return PostService.deletePosts(ids);
    }

    @PostMapping("/insert")
    @ApiOperation("添加采购计划")
    public RespResult<String> addPost(PostQO PostQO) {
        return PostService.insert(PostQO);
    }

    @PutMapping("/update")
    @ApiOperation("修改采购计划")
    public RespResult<String> modifyPost(PostQO PostQO) {
        return PostService.modify(PostQO);
    }

    @GetMapping("/select")
    @ApiOperation("根据id查询采购计划")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "sid", value = "采购计划id", required = true)
    )
    public RespResult<PostVO> queryPostById(int sid) {
        return PostService.selectPostById(sid);
    }

}
